package cn.hfatec.shms.web.xm.xmFxhzb.service;

import java.util.List;
import java.util.HashMap;


import cn.hfatec.shms.web.WeekTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.xm.xmFxhzb.model.XmFxhzb;
import cn.hfatec.shms.web.xm.xmFxhzb.dao.XmFxhzbDao;
import cn.hfatec.shms.web.xm.xmFxhzb.model.XmFxhzbParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("XmFxhzbService")
public class XmFxhzbService {

    public static final String BEAN_ID = "XmFxhzbService";

    //注入Dao层
    @Resource(name = "XmFxhzbDao")
    private XmFxhzbDao xmFxhzbDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param xmFxhzbParams
     * @param page
     *
     */
    @Transactional
    public Table queryXmFxhzbTable(XmFxhzbParams xmFxhzbParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        String bzStart = null;
        if ((xmFxhzbParams.getBillStart() == null) || (xmFxhzbParams.getBillStart().isEmpty())) {
            bzStart = WeekTime.getBzstart();
            xmFxhzbParams.setBillStart(bzStart);
        } else {
            bzStart = xmFxhzbParams.getBillStart();
        }
        if ((xmFxhzbParams.getBillEnd() == null) || (xmFxhzbParams.getBillEnd().isEmpty())) {
            String riqiend = WeekTime.getBzend(bzStart);
            xmFxhzbParams.setBillEnd(riqiend);
        }
        params.put("params", xmFxhzbParams);
        return baseDao.queryTableByPage("queryXmFxhzb", params, page);
    }

    /**
     *
     * 插入数据
     * @param xmFxhzb
     *
     */
    @Transactional
    public void saveXmFxhzb(XmFxhzb xmFxhzb) {
        if(xmFxhzb.getId() != null) {
            XmFxhzb result = getXmFxhzb(xmFxhzb.getId());
            if(result != null) {
                xmFxhzbDao.update(xmFxhzb);
            } else {
                xmFxhzbDao.insert(xmFxhzb);
            }
        } else {
            xmFxhzbDao.insert(xmFxhzb);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteXmFxhzb(Integer id) {

        xmFxhzbDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param xmFxhzbList
     *
     */
    @Transactional
    public void deleteXmFxhzbBatch(List<String> xmFxhzbList) {
        for(String id : xmFxhzbList) {
            deleteXmFxhzb(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public XmFxhzb getXmFxhzb(Integer id) {

        return xmFxhzbDao.getXmFxhzbById(id);
    }
}